<!-- 功能：新增静态路由弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月13日 00:06:52 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="新增静态路由" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel" >
    <a-form :label-col="{ span: 6 }" :wrapper-col="{span: 14}">
      <a-form-item label="接口" v-bind="validateInfos.port">
        <a-select v-model:value="modelRef.port" placeholder="请选择接口">
          <a-select-option value="enp5s0f0">enp5s0f0</a-select-option>
          <a-select-option value="enp5s0f1">enp5s0f1</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="网络设置" v-bind="validateInfos.networdSetting">
        <a-input v-model:value="modelRef.networdSetting" placeholder="请输入网络设置" />
      </a-form-item>
      <a-form-item label="掩码" v-bind="validateInfos.yanMa">
        <a-input v-model:value="modelRef.yanMa" placeholder="请输入掩码" />
      </a-form-item>
      <a-form-item label="网关" v-bind="validateInfos.wangGuan">
        <a-input v-model:value="modelRef.wangGuan" placeholder="请输入网关" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

import { Form } from 'ant-design-vue'

const useForm = Form.useForm

const modelRef = reactive({
  port: 'enp5s0f0',
  networdSetting: '',
  yanMa: '',
  wangGuan: ''
})

const rulesRef = reactive({
  port: [
    {
      required: true,
      message: '请选择接口'
    }
  ],
  networdSetting: [
    {
      required: true,
      message: '请输入网络设置'
    }
  ],
  yanMa: [
    {
      required: true,
      message: '请输入掩码'
    }
  ],
  wangGuan: [
    {
      required: true,
      message: '请输入网关'
    }
  ]
})

const { resetFields, validate, validateInfos, mergeValidateInfo } = useForm(modelRef, rulesRef)
const onSubmit = () => {
  validate()
    .then(() => {
      console.log('新增静态路由>>' , toRaw(modelRef))
      onCancel()
    })
    .catch(err => {
      console.log('error', err)
    })
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
</style>